package cn.tedu.boot42.controller;

import cn.tedu.boot42.entity.User;
import cn.tedu.boot42.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    UserMapper mapper;

    @RequestMapping("/insert")
    public void insert(User user){
        mapper.insert(user);
    }

    @RequestMapping("/select")
    public List<User> select(){

        //当方法return的类型为自定义对象或集合时,
        //SpringMVC框架会自动将集合或对象转成Json格式的字符串
        //然后将字符串再转换成二进制数据通过网络传输给客户端

       return mapper.select();
    }

    @RequestMapping("/delete")
    public void delete(int id){
        mapper.deleteById(id);
    }

    @RequestMapping("/selectById")
    public User selectById(int id){
        return mapper.selectById(id);
    }

    @RequestMapping("/update")
    public void update(User user){
        mapper.update(user);
    }
}
